<?php

namespace App\Http\Controllers\Api\V1;

use App\Models\Category;
use App\Models\Product;
use Brick\Math\RoundingMode;
use App\Services\Cache\ProductCache;
use App\Http\Controllers\Api\V1\Resources\ProductResource;
use App\Http\Controllers\Api\V1\Resources\ProductListResource;

class ProductsController extends Controller
{
	public function index()
	{

		$category  = Category::find(request('cid'));
		
		$products = app(ProductCache::class)->products($category);

		return ProductListResource::collection($products);

		
	}
	
	public function search()
	{
		$keyword = request('keyword');
		$products = Product::sSearchFromCache($keyword);
		return response()->json($products);
	}
	
	public function show($id)
	{
		
		$product = app(ProductCache::class)->product($id);
		return new ProductResource($product);
	}


	public function myCommandProducts()
	{

		$category  = Category::find(request('cid'));
		$products = app(ProductCache::class)->products($category);

		return ProductResource::collection($products);

		
	}
}
